﻿<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:this="clr-namespace:Microsoft.Research.ScientificWorkflow.UIDesigner.Import"
    xmlns:controls="clr-namespace:Microsoft.Research.ScientificWorkflow.UIDesigner"
	x:Class="Microsoft.Research.ScientificWorkflow.UIDesigner.Import.ImportDialog" WindowStartupLocation="CenterScreen"
    AllowsTransparency="True" ResizeMode="CanResizeWithGrip" WindowStyle="None" AutomationProperties.AutomationId="ImportDialog"
	Width="675" Height="600" MinWidth="675" MinHeight="600" MaxWidth="800" MaxHeight="600" ShowInTaskbar="False" Icon="Images\ImportIcon.png">

    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"></BooleanToVisibilityConverter>
        <this:NegateBooleanValueConverter x:Key="boolNegationConverter"></this:NegateBooleanValueConverter>
        <DataTemplate x:Key="referencesListTemplate">
            <TextBlock Text="{Binding}" ToolTip="{Binding}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"></TextBlock>
        </DataTemplate>
        <Style x:Key="PopupCloseButton" BasedOn="{x:Null}" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Rectangle Fill="#FFCCCCCC" Stroke="{x:Null}" RadiusX="4.5" RadiusY="4.5" x:Name="rectangle"/>
                            <Rectangle Fill="#FF4F4F4F" Stroke="{x:Null}" RadiusX="0" RadiusY="0" Margin="8,3.5,7,3.5" RenderTransformOrigin="0.5,0.5">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="-34.039"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                            <Rectangle Fill="#FF4F4F4F" Stroke="{x:Null}" RadiusX="0" RadiusY="0" RenderTransformOrigin="0.5,0.5" Margin="8,3.5,7,3.5">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="-1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="34.039"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Fill" TargetName="rectangle" Value="#FFADADAD"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="ReferencesTemplate">
            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10,0,10">
                <ListBox AutomationProperties.AutomationId="FileReferencesList" Width="240" Height="Auto" MaxHeight="90" MinHeight="40"
                        SelectionChanged="OnReferenceSelected" Tag="{Binding Path=FilePath}"
                        Visibility="Visible" ItemsSource="{Binding Path=DisplayReferences}" ItemTemplate="{StaticResource referencesListTemplate}"/>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
                    <Button AutomationProperties.AutomationId="AddReferenceButton" Width="60" Content="Add" Click="OnAddReference" Tag="{Binding Path=FilePath}"/>
                    <Button AutomationProperties.AutomationId="RemoveReferenceButton" Width="60" Content="Remove" Margin="5,0,0,0" Click="OnRemoveReference"
                            Tag="{Binding Path=FilePath}" Visibility="{Binding Path=ReferenceVisibility}"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="ReferencesTemplateForSaveToRegistry">
            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10,0,10">
                <ListBox AutomationProperties.AutomationId="FileReferencesList" Width="240" Height="Auto" MaxHeight="90" MinHeight="40"
                        SelectionChanged="OnReferenceSelected" Tag="{Binding Path=FilePath}"
                        Visibility="{Binding Path=ReferenceVisibility}" ItemsSource="{Binding Path=DisplayReferences}" ItemTemplate="{StaticResource referencesListTemplate}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>

    <Grid>
        <Border BorderBrush="#FFBDBDBD" BorderThickness="1,1,2,2" CornerRadius="4,4,4,4">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFF7F7F7" Offset="0"/>
                    <GradientStop Color="#FFF1F1F1" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="38"/>
                </Grid.RowDefinitions>

                <Button Name="btnImport" IsDefault="True" HorizontalAlignment="Right" Width="70" Content="Import" Margin="0,0,85,0" VerticalAlignment="Center" Grid.Row="2"/>
                <Button Name="btnCancel" IsCancel="True" HorizontalAlignment="Right" Width="70" Content="Cancel" Margin="0,0,10,0" VerticalAlignment="Center" Grid.Row="2"/>

                <Border MouseLeftButtonDown="BorderMouseLeftButtonDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Grid.Row="0" CornerRadius="4,4,0,0">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFF7F7F7" Offset="0"/>
                            <GradientStop Color="#FFE9E9E9" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid>
                        <TextBlock Name="txtTitle" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" FontSize="14" Foreground="#FF5F5F5F" Text="Import Workflow" TextWrapping="Wrap"/>
						<Button Name="btnClose" HorizontalAlignment="Right" Margin="0,5.5,5,5.5" Style="{DynamicResource PopupCloseButton}" Width="17" Content="Button"/>
					</Grid>
                </Border>

                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" Background="#FFFFFFFF">
                    <GroupBox Name="grpWorkflowDetails" Header="Workflow Details" Visibility="Collapsed" Grid.Row="0" BorderThickness="1,1,1,1" BorderBrush="#FFD6D6D6" Margin="10,10,10,0">
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="90"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <TextBlock HorizontalAlignment="Left" Text="Name:" TextWrapping="Wrap" Margin="48,4,0,0" VerticalAlignment="Top"/>
							<TextBox Name="txtWorkflowName" AutomationProperties.AutomationId="WorkflowName" MaxLength="75" HorizontalAlignment="Left" Width="300" TextWrapping="NoWrap" Margin="0,2,0,0" Grid.Column="1" VerticalAlignment="Top"/>
                            <DockPanel Name="dckWorkflowNameError" Visibility="Collapsed" HorizontalAlignment="Left" Margin="-7,7,0,0" Grid.Column="1" VerticalAlignment="Top">
                                <Grid DockPanel.Dock="Left" Margin="2,0" Width="12" Height="12">
                                    <Ellipse Fill="#FFC42A2A" Stroke="{x:Null}"/>
                                    <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="4.94,2.235,4.644,5.12" Data="M11.701627,8.0009042 L12.372672,15.173164 14.011686,15.241177 14.56827,7.8270056 z"/>
                                    <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="5.121,0,4.779,1.746" VerticalAlignment="Bottom" Height="2.1" Data="M11.395564,17.238573 L14.853121,17.333691 14.771832,21.163108 11.102494,20.999791 z"/>
                                </Grid>
                            </DockPanel>
                            
							<TextBlock Text="Type:" TextWrapping="Wrap" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="54,6,0,0"/>
                            <ComboBox Name="cmbWorkflowType" AutomationProperties.AutomationId="WorkflowType" HorizontalAlignment="Left" VerticalAlignment="Top" IsSynchronizedWithCurrentItem="True" Grid.Row="1" Grid.Column="1" Width="300" Margin="0,5,0,0">
                                <ComboBox.ToolTip>
                                    <TextBlock>
                                        <Run Text="Interactive workflows require some sort of user action to run."/>
                                        <LineBreak/>
                                        <Run Text="Non-interactive workflows run silently in the background."/>
                                    </TextBlock>
                                </ComboBox.ToolTip>
                                
								<ComboBoxItem Content="Interactive"/>
								<ComboBoxItem Content="Non Interactive" IsSelected="True"/>
							</ComboBox>

                            <TextBlock HorizontalAlignment="Left" Text="Description:" TextWrapping="Wrap" Grid.Row="2" Margin="19,5,0,0" VerticalAlignment="Top"/>
							<TextBox Name="txtWorkflowDesc" TextWrapping="Wrap" MaxLength="300" AutomationProperties.AutomationId="WorkflowDescription" AcceptsReturn="True" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" Width="300" Grid.Column="1" Grid.Row="2" Height="50" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled"/>
                            	
                            <TextBlock Text="Category:" TextWrapping="Wrap" Margin="30,6,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Row="3"/>
							<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Grid.Row="3" Margin="0,5,0,0">
								<Grid.RowDefinitions>
									<RowDefinition Height="Auto"/>
								</Grid.RowDefinitions>
                                
								<TextBox Name="txtCategory" AutomationProperties.AutomationId="WorkflowCategory" TextWrapping="NoWrap" Margin="0,0,0,0" Width="300" HorizontalAlignment="Left" VerticalAlignment="Top" IsEnabled="False"/>
								<Button Name="btnCategoryBrowse" AutomationProperties.AutomationId="WorkflowCategoryBrowse" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Browse..." Width="70" Margin="305,0,0,0"/>
							    <DockPanel Name="dckCategoryError" ToolTip="Select a category for the workflow" Visibility="Collapsed" HorizontalAlignment="Left" Margin="-7,4,0,0" Grid.Column="1" VerticalAlignment="Top">
                                    <Grid DockPanel.Dock="Left" Margin="2,0" Width="12" Height="12">
                                        <Ellipse Fill="#FFC42A2A" Stroke="{x:Null}"/>
                                        <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="4.94,2.235,4.644,5.12" Data="M11.701627,8.0009042 L12.372672,15.173164 14.011686,15.241177 14.56827,7.8270056 z"/>
                                        <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="5.121,0,4.779,1.746" VerticalAlignment="Bottom" Height="2.1" Data="M11.395564,17.238573 L14.853121,17.333691 14.771832,21.163108 11.102494,20.999791 z"/>
                                    </Grid>
                                </DockPanel>
                            </Grid>
						</Grid>
                    </GroupBox>
                    
                    <GroupBox Header="Select Files" BorderThickness="1,1,1,1" Grid.Row="1" BorderBrush="#FFD6D6D6" Margin="10,10,10,0">
                        <StackPanel HorizontalAlignment="Stretch" Height="32" VerticalAlignment="Top">
                            <Grid Height="Auto" Margin="0,5,0,5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="90"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="Location:" TextWrapping="Wrap" Margin="33,2,0,0"/>
								<TextBox Name="txtLocation" IsEnabled="False" HorizontalAlignment="Left" TextWrapping="NoWrap" Width="300" Margin="0,0.04,0,0" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top"/>
								<Button Name="btnBrowse" AutomationProperties.AutomationId="BrowseFiles" TabIndex="0" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="Browse..." Width="70" Grid.Column="1" Margin="305,0,0,0"/>
							    <DockPanel Name="dckLocationError" Visibility="Collapsed" HorizontalAlignment="Left" Margin="-7,5,0,0" Grid.Column="1" VerticalAlignment="Top">
                                    <Grid DockPanel.Dock="Left" Margin="2,0" Width="12" Height="12">
                                        <Ellipse Fill="#FFC42A2A" Stroke="{x:Null}"/>
                                        <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="4.94,2.235,4.644,5.12" Data="M11.701627,8.0009042 L12.372672,15.173164 14.011686,15.241177 14.56827,7.8270056 z"/>
                                        <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="5.121,0,4.779,1.746" VerticalAlignment="Bottom" Height="2.1" Data="M11.395564,17.238573 L14.853121,17.333691 14.771832,21.163108 11.102494,20.999791 z"/>
                                    </Grid>
                                </DockPanel>
							</Grid>
                        </StackPanel>
                    </GroupBox>
                    
                    <GroupBox Name="grpAssociatedFiles" Header="Workflow Associated Files" Grid.Row="2" BorderThickness="1,1,1,1" BorderBrush="#FFC4C4C4" Background="#FFFFFFFF" Margin="10,10,10,0" Height="280">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>

                            <controls:SortListView x:Name="lstDependencies" AutomationProperties.AutomationId="DependenciesList" BorderBrush="#FFCCCCCC" Grid.Row="0" Margin="10,10,10,4"
                                      ItemsSource="{Binding ElementName=advancedImportControl, Path=FileReferences}" SelectionMode="Single">                                
                                <ListView.View>
                                    <GridView>
                                        <controls:SortListViewColumn MinimumWidth="150" AutomationProperties.AutomationId="FileColumn" x:Name="colFile" Header="Name" Width="150">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock AutomationProperties.AutomationId="FileName" Text="{Binding Path=DisplayName}" ToolTip="{Binding Path=DisplayName}"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortListViewColumn>

                                        <controls:SortListViewColumn MinimumWidth="320" AutomationProperties.AutomationId="OperationColumn" x:Name="colOperation" Header="Operation" Width="320">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0">
                                                        <CheckBox Content="Update Existing" Margin="0,5,0,5" Checked="CheckBoxChecked" Unchecked="CheckBoxUnchecked" IsEnabled="{Binding Path=CopyExistsInRegistry, Converter={StaticResource boolNegationConverter}}" IsChecked="{Binding Path=UpdateExisting, UpdateSourceTrigger=Explicit}" AutomationProperties.AutomationId="UpdateExistingCheckbox"/>
                                                        
                                                        <Border BorderBrush="{x:Null}" BorderThickness="1,1,1,1" CornerRadius="5,5,5,5" Background="{x:Null}" Visibility="{Binding Path=ShowAssemblyToUpdate, Converter={StaticResource booleanToVisibilityConverter}}" Width="400">
                                                            <Grid Margin="0,5,5,5">
                                                                <Grid.ColumnDefinitions>
                                                                    <ColumnDefinition Width="90"/>
                                                                    <ColumnDefinition Width="*"/>
                                                                </Grid.ColumnDefinitions>
                                                                <Grid.RowDefinitions>
                                                                    <RowDefinition Height="Auto"/>
                                                                    <RowDefinition Height="Auto"/>
                                                                    <RowDefinition Height="Auto"/>
                                                                </Grid.RowDefinitions>
                                                                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="Name:" TextWrapping="Wrap" Margin="0,3,5,0"/>
				                                                <TextBox IsReadOnly="True" HorizontalAlignment="Left" Text="{Binding Path=AssemblyInRegistryToUpdate.Name}" ToolTip="{Binding Path=AssemblyInRegistryToUpdate.Name}" Width="135" Margin="0,0.04,0,0" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" AutomationProperties.AutomationId="AssemblyNameToUpdate"/>
				                                                <Button HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="Change" Width="70" Grid.Column="1" Margin="140,0,0,0" Click="ChangeClick" AutomationProperties.AutomationId="ChangeAssemblyButton"/>
				                                                <TextBlock HorizontalAlignment="Left" Text="Imported Date:" TextWrapping="Wrap" Margin="0,5,5,0" Grid.Row="1" VerticalAlignment="Top"/>
				                                                <TextBlock HorizontalAlignment="Left" Text="Imported By:" TextWrapping="Wrap" Margin="0,5,5,0" Grid.Row="2" VerticalAlignment="Top"/>
				                                                <TextBlock HorizontalAlignment="Left" Text="{Binding Path=AssemblyInRegistryToUpdate.ImportedTime}" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Margin="0,5,0,0"/>
				                                                <TextBlock HorizontalAlignment="Left" Text="{Binding Path=AssemblyInRegistryToUpdate.ImportedBy}" TextWrapping="Wrap" Margin="0,5,0,0" Grid.Column="1" Grid.Row="2" VerticalAlignment="Top"/>
			                                                </Grid>
                                                        </Border>
                                                    </StackPanel>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortListViewColumn>
                                    </GridView>
                                </ListView.View>
                            </controls:SortListView>

                            <StackPanel Grid.Row="1" Margin="0,0,9,0" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                                <Button Name="btnRemove" AutomationProperties.AutomationId="RemoveButton" Content="Remove" Width="70" Margin="0,0,5,0"/>
                                <Button Name="btnDependencies" AutomationProperties.AutomationId="DependenciesButton" Content="Show Dependencies" Tag="Show" Width="150"/>
                            </StackPanel>
                        </Grid>
                    </GroupBox>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Window>